package BinarySearchTree;

import java.util.*;

public class Test {

    public static void main(String[] args) {
        Set<String> set = new HashSet<>();
        set.add("apple");  // 添加"apple"
        set.add("banana"); // 添加"banana"
        set.add("apple");  // "apple"已经在集合中，不会被重复添加
        System.out.println(set); // 输出 [apple, banana]

        /*set.clear();
        System.out.println(set);*/

        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        System.out.println(set.size());
        /*set.remove("apple");
        System.out.println(set);*/
        /*set.clear();
        System.out.println(set.isEmpty());*/
        Object[] array = set.toArray();
        System.out.println(Arrays.toString(array));

        /*Set<String> set2 = new HashSet<>();
        set2.add("apple");
        set2.add("banana");
        set2.add("hellpo");
        System.out.println(set.containsAll(set2));*/

        Set<String> set2 = new HashSet<>();
        set2.add("banana");
        set2.add("apple");
        set2.add("qhwafuh");
        set2.add("aaaaaaaa");
        set.addAll(set2);
        System.out.println(set);


    }

    public static void main4(String[] args) {
        Map<String, String> m = new TreeMap<>();
        // put(key, value):插入key-value的键值对
        // 如果key不存在，会将key-value的键值对插入到map中,返回null
        m.put("林冲", "豹子头");
        m.put("鲁智深", "花和尚");
        m.put("武松", "行者");
        m.put("宋江", "及时雨");
        String str = m.put("李逵", "黑旋风");
        System.out.println(m.size());
        System.out.println(m);
        System.out.println(str);
        str = m.put("xiba","qiba");
        System.out.println(str);
        System.out.println(m);

    }


    public static void main2(String[] args) {
        Map<String, Integer> map = new TreeMap<>();
        map.put("xiaoming", 99);
        map.put("gemda", 12);
        map.put("zhaosi", 35);
        //System.out.println(map);
        //System.out.println(map.get("xiaoming"));
        //Set<Map.Entry<String,Integer>> set = map.entrySet();
        /*Iterator iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }*/

        /*for (Map.Entry<String,Integer> entry:set) {
            System.out.println("key: "+entry.getKey()+"   val:"+entry.getValue());
        }*/


        System.out.println(map.get("xiaoming"));
        System.out.println(map.getOrDefault("xiaomin", 12));
        //map.remove("xiaoming");
        //System.out.println(map);

        Set<String> keys = map.keySet();
        System.out.println(keys);

        Collection<Integer> values = map.values();
        System.out.println(values);
        System.out.println(map);
        Set<Map.Entry<String, Integer>> set = map.entrySet();
        System.out.println(set);

        System.out.println(map.containsKey("xiaomig"));
        System.out.println(map.containsValue(99));


    }

    public static void main1(String[] args) {
        int[] array = {4, 2, 1, 6, 9, 8, 7, 3, 0};
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        for (int i = 0; i < array.length; i++) {
            binarySearchTree.insert(array[i]);
        }
        //binarySearchTree.Tree(binarySearchTree.root);
        System.out.println(binarySearchTree.search(7));
        binarySearchTree.remove(7);
        System.out.println(binarySearchTree.search(7));
    }


}
